home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / netlog-1.02 / udplogger / pktfilt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-20  |  1.4 KB  |  63 lines

  1. /*
  2.      udplogger - A UDP traffic logger
  3.      Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
  4.  
  5.      Please see the file `COPYING' for the complete copyright notice.
  6.  
  7. pktfilt.c - 03/20/93
  8.  
  9. */
  10. #include <stdio.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <net/nit_pf.h>
  14. #include <net/packetfilt.h>
  15. #include <netinet/in.h>
  16. #include <sys/socket.h>
  17. #include <net/if.h>
  18. #include <netinet/if_ether.h>
  19. #include <sys/stropts.h>
  20. #include <netdb.h>
  21.  
  22. #define offsetof(T, m) ((size_t)&(((T *)0)->m))
  23.  
  24. /*
  25.   Rename some of the packet filter operators so that
  26.    the names reflect what they actually do
  27. */
  28.  
  29. /* Short circuit if equal and keep packet */
  30. #define ENF_CEQ ENF_COR
  31. /* Short circuit if not equal and keep packet */
  32. #define ENF_CNE ENF_CNAND
  33. /* Short circuit if equal and reject packet */
  34. #define ENF_CREQ ENF_NOR
  35. /* Short circuit if not equal and reject packet */
  36. #define ENF_CRNE ENF_CAND
  37.  
  38. void
  39. pushfilter(int fd)
  40. {
  41.      struct packetfilt pf;
  42.      u_short *ptr;
  43.      struct servent *se;
  44.  
  45.      pf.Pf_Priority = 0;
  46.      ptr = pf.Pf_Filter;
  47.      *ptr++ = ENF_PUSHWORD + 6;
  48.      *ptr++ = ENF_PUSHLIT|ENF_CRNE;
  49.      *ptr++ = htons(ETHERTYPE_IP);
  50.      *ptr++ = ENF_PUSHWORD + 11;
  51.      *ptr++ = ENF_PUSHLIT|ENF_AND;
  52.      *ptr++ = 0xff;
  53.      *ptr++ = ENF_PUSHLIT|ENF_CRNE;
  54.      *ptr++ = 17; /* UDP */
  55.  
  56.      pf.Pf_FilterLen = ptr - &pf.Pf_Filter[0];
  57.  
  58.      if(ioctl(fd, NIOCSETF, &pf) == -1)
  59.       perror("pf setf");
  60. }
  61.  
  62.      
  63.